using System;
using System.Collections.Generic;
using System.Text;
using Objects;

namespace DAL
{
    public class DALDuyet
    {
        public List<Duyet> GetByTrangThaiDuyet(int trangthaiDuyet)
        {
            List<Duyet> ListDuyet = new List<Duyet>();

            clsDataAccess acc = new clsDataAccess();

            string[] sname = new string[] {"@Status","@TrangThaiDuyet"};
            string[] vname = new string[] { Common.Myconst.HOATDONG.ToString() ,trangthaiDuyet.ToString() };
            System.Data.DataSet ds = acc.CommandSelect("[Duyet_GetByTrangThaiDuyet]", sname, vname);

            Duyet Item = new Duyet();

            for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
            {
                System.Data.DataRow dr = ds.Tables[0].Rows[i];
                ListDuyet.Add((Item.Populate(dr)));
            }
            return ListDuyet;
        }

        public int Insert(Duyet Item)
        {
            clsDataAccess acc = new clsDataAccess();
            string[] sname = new string[] { "@IdDangKy", "@IdNguoiDung", "@GhiChu", "@TrangThaiduyet", "@Status", "@SapXep" };
            string[] vname = new string[] { Item.IdDangKy.ToString(), Item.IdNguoiDung.ToString(), Item.GhiChu.ToString(), Item.TrangThaiDuyet.ToString(), Common.Myconst.HOATDONG.ToString(), "0" };
            return acc.InsertUpdateDetete("Duyet_Insert", sname, vname);

        }

        public Duyet GeById(int Id)
        {
            List<Duyet> ListDuyet = new List<Duyet>();

            clsDataAccess acc = new clsDataAccess();

            string[] sname = new string[] { "@Status", "@Id" };
            string[] vname = new string[] { Common.Myconst.HOATDONG.ToString(), Id.ToString() };
            System.Data.DataSet ds = acc.CommandSelect("Duyet_GetById", sname, vname);

            Duyet Item = new Duyet();


            System.Data.DataRow dr = ds.Tables[0].Rows[0];
            return Item.Populate(dr);
        }

        public Duyet GeByIdDangKy(int Id)
        {
            List<Duyet> ListDuyet = new List<Duyet>();

            clsDataAccess acc = new clsDataAccess();

            string[] sname = new string[] { "@Status", "@IdDangKy" };
            string[] vname = new string[] { Common.Myconst.HOATDONG.ToString(), Id.ToString() };
            System.Data.DataSet ds = acc.CommandSelect("Duyet_GetByIdDangKy", sname, vname);

            Duyet Item = new Duyet();


            System.Data.DataRow dr = ds.Tables[0].Rows[0];
            return Item.Populate(dr);
        }

        public int Update_Duyet(int id, int idDangKy, int idNguoiDung,DateTime NgayDuyet,String GhiChu, int TrangThaiDuyet, int Status, int SapXep)
        {
            clsDataAccess acc = new clsDataAccess();

            string[] sname = new string[] { "@Id", "@IdDangKy", "@IdNguoiDung","@NgayDuyet", "@GhiChu" ,"@TrangThaiDuyet","@Status", "@SapXep" };
            string[] vname = new string[] { id.ToString(), idDangKy.ToString(), idNguoiDung.ToString(),NgayDuyet.ToString(),GhiChu.ToString(),TrangThaiDuyet.ToString() ,Status.ToString(), SapXep.ToString() };
            return acc.InsertUpdateDetete("Duyet_Update", sname, vname);

        }
    }
}
